package library.web.servlet.ajax;

import com.alibaba.fastjson2.JSON;
import library.domain.Book;
import library.domain.User;
import library.persistence.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

public class EditUser extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int type = Integer.parseInt(req.getParameter("type")) ;
        System.out.println(type);

        UserService userService = new UserService();
        if(type == 1){  //刷新页面，显示所有用户
            List<User> bookList = userService.getAllUser();
            String jsonString = JSON.toJSONString(bookList);
            resp.setContentType("text/json;charset=UTF-8");
            PrintWriter out = resp.getWriter();
            out.print(jsonString);
        }else if(type == 2){


        }
    }
}
